package com.bupt.controller.common;

import com.bupt.annotation.AccessLimit;

import com.bupt.constants.ResponseResult;
import com.bupt.dto.sys.LoginUserDto;
import com.bupt.dto.sys.UserDto;
import com.bupt.exception.BaseException;
import com.bupt.service.common.impl.PlanResultService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 规划的结果查询
 *
 * @author breakpoint/赵先生 <zlgtop@163.com>
 * create on 2021/04/17
 */
@Slf4j
@Api(tags = {"规划结果"})
@RestController
@RequestMapping("/api/projects/{projectId}")
public class PlanResultController {

    @Autowired
    @Qualifier("planResultService")
    private PlanResultService planResultService;

    @ApiOperation("规划的结果查询")
    @GetMapping("/service/{serviceId}/plan")
    @AccessLimit(interfaceName = "获取规划的结果")
    public Object getPlanResult(@ApiIgnore LoginUserDto loginUserDto, @PathVariable("projectId")
            String pId,@PathVariable("serviceId") String serviceId) {
        try {
            return ResponseResult.createOK(planResultService.getPlanResult(pId,serviceId));
        } catch (BaseException e) {
            log.error("处理数据异常 pid:{}", pId, e);
            return ResponseResult.createFail(e.getMessage());
        }
    }

    @ApiOperation("根据链路的ID查询承载的业务信息")
    @GetMapping("/links/{linkType}/{linkId}")
    @AccessLimit(interfaceName = "根据链路的ID查询承载的业务信息")
    public Object getPlanResultService(@ApiIgnore LoginUserDto loginUserDto,
                                       @PathVariable("linkId") String linkId,
                                       @PathVariable("linkType") String layer,
                                       @PathVariable("projectId") String pId) {
        try {
            return ResponseResult.createOK(planResultService.getPlanResultService( linkId,pId));
        } catch (BaseException e) {
            log.error("处理数据异常 pid:{}", pId, e);
            return ResponseResult.createFail(e.getMessage());
        }
    }
    @ApiOperation("查询规划后的端口占用情况")
    @GetMapping("/{nodeId}/ports")
    @AccessLimit(interfaceName = "根据链路的ID查询承载的业务信息")

    public Object getPlanResultServicePort(@ApiIgnore LoginUserDto loginUserDto,
                                            @PathVariable("projectId") String pId,
                                           @PathVariable("nodeId") String nodeId) {
        try {
            return ResponseResult.createOK(planResultService.getPlanResultPort(pId,nodeId));
        } catch (BaseException e) {
            log.error("处理数据异常 pid:{}", pId, e);
            return ResponseResult.createFail(e.getMessage());
        }
    }



}
